import request from '@/utils/axios'

// Unicode转换相关类型定义
export interface UnicodeConvertRequest {
  content: string
  type: 'toUnicode' | 'fromUnicode'
}

// AES加解密相关类型定义
export interface AESProcessRequest {
  content: string
  key: string
  operation: 'encrypt' | 'decrypt'
  mode?: 'ECB' | 'CBC'
  padding?: string
  iv?: string
}

// DES加解密相关类型定义
export interface DESProcessRequest {
  content: string
  key: string
  operation: 'encrypt' | 'decrypt'
  mode?: 'ECB' | 'CBC'
  padding?: string
  iv?: string
}

// URL编码解码相关类型定义
export interface URLProcessRequest {
  content: string
  operation: 'encode' | 'decode'
  charset?: string
}

// 通用响应类型
export interface CryptoResponse<T = string> {
  code: number
  message: string
  data: T
}

// 加解密API类
export class CryptoApi {
  /**
   * Unicode编码转换
   * @param params 转换参数
   * @returns Promise<CryptoResponse>
   */
  static unicodeConvert(params: UnicodeConvertRequest): Promise<CryptoResponse> {
    return request({
      url: '/crypto/unicode/convert',
      method: 'post',
      data: params
    })
  }

  /**
   * AES加解密处理
   * @param params 处理参数
   * @returns Promise<CryptoResponse>
   */
  static aesProcess(params: AESProcessRequest): Promise<CryptoResponse> {
    return request({
      url: '/crypto/aes/process',
      method: 'post',
      data: params
    })
  }

  /**
   * DES加解密处理
   * @param params 处理参数
   * @returns Promise<CryptoResponse>
   */
  static desProcess(params: DESProcessRequest): Promise<CryptoResponse> {
    return request({
      url: '/crypto/des/process',
      method: 'post',
      data: params
    })
  }

  /**
   * URL编码解码处理
   * @param params 处理参数
   * @returns Promise<CryptoResponse>
   */
  static urlProcess(params: URLProcessRequest): Promise<CryptoResponse> {
    return request({
      url: '/crypto/url/process',
      method: 'post',
      data: params
    })
  }
}

// 导出所有类型和API
export default CryptoApi